package database.service;

import common.Message;
import database.DAO.OfflineMessageDAO;

import java.util.List;

public class OfflineMessageService {
    private OfflineMessageDAO offlineMessageDAO=new OfflineMessageDAO();

    UserService userService=new UserService();

    public List<Object> queryByName(String userName){
        Long id = commonService.queryIdByUserName(userName);
        return offlineMessageDAO.queryColumnList(
                "select message from offline_message where id=?", id
        );
    }

    public int updateOfflineMessageByUserName(String userName,Message offlineMessage){

        Long id = commonService.queryIdByUserName(userName);
        return offlineMessageDAO.update("insert into offline_message values(?,?)",id,offlineMessage);
    }

    public int deleteOfflineMessageByUserName(String userName){
        Long id = commonService.queryIdByUserName(userName);
        return offlineMessageDAO.update("delete from offline_message where id=?",id);
    }
}
